{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8a340f1a-f6d6-4ca5-a8f1-d53f6eafa00e",
   "metadata": {},
   "source": [
    "<a align=\"center\" href=\"https://gitee.com/CV_Lab/opencv_webcam\" target=\"_blank\" alt=\"Simple Icons\" >\n",
    "<img src=\"https://gitee.com/CV_Lab/opencv_webcam/attach_files/952125/download/opencv-webcam-script_logo.png\"></a>\n",
    "\n",
    "<h1>🔥 opencv-webcam-script v0.8（Jupyter版）</h1>\n",
    "<h2>创建人：曾逸夫</h2>\n",
    "<h2>创建时间：2022-04-01</h2>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "68e88aa6-99c8-42b9-a189-70e42e7e6460",
   "metadata": {},
   "source": [
    "<a href=\"./CodeCheck.md\"><img src=\"https://img.shields.io/badge/CodeCheck-passing-success\" alt=\"code check\" /></a>\n",
    "<a href=\"https://gitee.com/CV_Lab/opencv_webcam/releases/v0.8\"><img src=\"https://img.shields.io/badge/Releases-v0.8-green\" alt=\"Releases Version\" /></a>\n",
    "<a href=\"https://pypi.org/project/opencv-webcam-script/0.8.0/\"><img src=\"https://img.shields.io/badge/PyPI-v0.8.0-brightgreen?logo=pypi\" alt=\"PyPI\" /></a>\n",
    "<a href=\"https://hub.docker.com/r/zengdockerdocker/opencv-webcam-script\"><img src=\"https://img.shields.io/badge/docker-v0.8-blue?logo=docker\" alt=\"Docker\" /></a>\n",
    "<a href=\"./tutorial/ows_podman.md\"><img src=\"https://img.shields.io/badge/Podman-v0.8-blueviolet?logo=podman\" alt=\"Podman\" /></a>\n",
    "<a href=\"https://gitee.com/CV_Lab/opencv_webcam/blob/master/tutorial/ows_jupyter.ipynb\"><img src=\"https://img.shields.io/badge/Jupyter-v0.8-orange?logo=jupyter\" alt=\"Jupyter\" /></a>\n",
    "<a href=\"https://gitee.com/CV_Lab/opencv_webcam/blob/master/LICENSE\"><img src=\"https://img.shields.io/badge/License-GPL--3.0-blue\" alt=\"License\" /></a>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8664eddc-e1b4-491e-a6b8-e21f98a960d5",
   "metadata": {},
   "source": [
    "<a href=\"./CodeSecurity.md\"><img src=\"https://img.shields.io/badge/CodeSecurity-passing-brightgreen\" alt=\"Code Security\" /></a>\n",
    "<a href=\"#\"><img src=\"https://img.shields.io/badge/Python-3.8%2B-blue?logo=python\" alt=\"Python Version\" /></a>\n",
    "<a href=\"https://snyk.io/advisor/python/opencv-webcam-script\"><img src=\"https://snyk.io/advisor/python/opencv-webcam-script/badge.svg\" alt=\"PyPI Package Health\"></a>\n",
    "<a href=\"https://github.com/PyCQA/bandit\"><img src=\"https://img.shields.io/badge/security-bandit-yellow.svg\" alt=\"security bandit\"></a>\n",
    "<a href=\"https://pycqa.github.io/isort/\"><img src=\"https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336\" alt=\"Imports: isort\"></a>\n",
    "<a href=\"https://github.com/PyCQA/flake8\"><img src=\"https://img.shields.io/badge/PyCQA-flake8-brightgreen\" alt=\"flake8\"></a>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b8dead12-d63c-442d-9e0f-d22a4372ce42",
   "metadata": {},
   "source": [
    "<a href='https://gitee.com/CV_Lab/opencv_webcam/stargazers'><img src='https://gitee.com/CV_Lab/opencv_webcam/badge/star.svg?theme=dark' alt='star'></img></a>\n",
    "<a href='https://gitee.com/CV_Lab/opencv_webcam/members'><img src='https://gitee.com/CV_Lab/opencv_webcam/badge/fork.svg?theme=dark' alt='fork'></img></a>\n",
    "<a href=\"https://hub.docker.com/r/zengdockerdocker/opencv-webcam-script\"><img src=\"https://img.shields.io/docker/pulls/zengdockerdocker/opencv-webcam-script?logo=docker\" alt=\"Docker Pulls\"></a>\n",
    "<a href=\"https://pypi.org/project/opencv-webcam-script\"><img src=\"https://static.pepy.tech/personalized-badge/opencv-webcam-script?period=total&units=international_system&left_color=grey&right_color=brightgreen&left_text=PyPI%20downloads\" alt=\"PyPI All Downloads\"></a>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5518d6e0-89ca-41d3-8be6-a3c76bc32709",
   "metadata": {},
   "source": [
    "<h3 align=\"center\">🚀 安装教程</h3>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f25bb221-dee2-499b-8879-f87ab35a9a60",
   "metadata": {},
   "source": [
    "#### 📌 克隆、安装依赖"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "89e07b19-7efa-4221-a220-f698b948cee2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 首先手动创建虚拟环境\n",
    "# conda create -n ows python==3.8 # 虚拟环境名称为ows\n",
    "# conda activate ows # 激活虚拟环境\n",
    "# 克隆\n",
    "!git clone https://gitee.com/CV_Lab/opencv_webcam.git\n",
    "%cd opencv_webcam\n",
    "# 安装\n",
    "%pip install -qr requirements.txt -U\n",
    "%pip install ipywidgets -U"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b2d663cc-48a1-411e-8646-50a9d29e5d34",
   "metadata": {},
   "source": [
    "❗ 注意：安装完成后，将`ows_jupyter.ipynb`放入`opencv_webcam`目录中进行下面的操作"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0a517ff5-9804-4059-8a9e-cb633725a023",
   "metadata": {},
   "source": [
    "<h3 align=\"center\">🔥 UI版</h3>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1bef9988-27b0-499f-9abb-9af0d5b85692",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "\n",
    "from ipywidgets import interactive, interact_manual\n",
    "from ipywidgets import Dropdown, FloatSlider, IntSlider, ToggleButtons, Text, Checkbox, IntText, BoundedIntText, IntRangeSlider\n",
    "from opencv_webcam import webcam_opencv\n",
    "\n",
    "# -------------------------------组件设置-------------------------------\n",
    "device_index = Text(value='0', placeholder='0,1,2 or RTSP', disabled=False, description='设备编号:')\n",
    "quit_key = Text(value='q', placeholder='退出键', disabled=False, description='退出键:')\n",
    "pause_key = Text(value='p', placeholder='暂停键', disabled=False, description='暂停键:')\n",
    "is_autoSaveFrame = Checkbox(value=False, disabled=False, indent=False, description='自动保存帧:')\n",
    "frame_saveDir = Text(value='WebcamFrame', placeholder='帧保存路径', disabled=False, description='帧保存路径:')\n",
    "frame_dirName = Text(value='frames', placeholder='帧目录名称', disabled=False, description='帧目录名称:')\n",
    "frame_nSave = BoundedIntText(value=1, min=1, step=1, description='n帧保存一次:', disabled=False)\n",
    "auto_frameNum = BoundedIntText(value=0, min=0, step=1, description='帧最大数:', disabled=False)\n",
    "is_handSaveFrame = Checkbox(value=False, disabled=False, indent=False, description='手动保存帧:')\n",
    "frame_capKey = Text(value='a', placeholder='帧捕获键', disabled=False, description='帧捕获键:')\n",
    "is_resizeFrame = Checkbox(value=False, disabled=False, indent=False, description='重塑帧:')\n",
    "resize_frame = Text(value='640,480', placeholder='重塑帧', disabled=False, description='自定义帧尺寸:')\n",
    "resizeRatio_frame = FloatSlider(min = 0.0, max = 1.0, value = 1.0, step = 0.1, continuous_update = False, description = '自定义帧缩放比:', orientation='horizontal', readout=True, readout_format='.1f')\n",
    "frame_namePrefix = Text(value='frame', placeholder='帧名前缀', disabled=False, description='帧前缀:')\n",
    "frame_saveStyle = Text(value='jpg', placeholder='jpg or png', disabled=False, description='帧保存类型:')\n",
    "jpg_quality = IntSlider(min = 0, max = 100, value = 95, step = 1, continuous_update = False, description = 'jpg质量系数:', orientation='horizontal', readout=True, readout_format='d')\n",
    "png_quality = IntSlider(min = 0, max = 9, value = 3, step = 1, continuous_update = False, description = 'png质量系数:', orientation='horizontal', readout=True, readout_format='d')\n",
    "# 日志管理\n",
    "logName = Text(value='ows.log', placeholder='日志名称', disabled=False, description='日志名称:')\n",
    "logMode = Text(value='a', placeholder='日志模式', disabled=False, description='日志模式:')\n",
    "# 帧压缩\n",
    "is_compress = Checkbox(value=False, disabled=False, indent=False, description='压缩帧')\n",
    "compressStyle = Text(value='zip', placeholder='压缩类型', disabled=False, description='压缩类型:')\n",
    "is_autoCompressName = Checkbox(value=False, disabled=False, indent=False, description='自动压缩命名:')\n",
    "compressName = Text(value='ows', placeholder='压缩名称', disabled=False, description='压缩名称:')\n",
    "compressMode = Text(value='w', placeholder='压缩模式', disabled=False, description='压缩模式:')\n",
    "# 去除背景色\n",
    "is_rmbgColor = Checkbox(value=False, disabled=False, indent=False, description='去除背景色:')\n",
    "rmbgColorMode = Text(value='green', placeholder='绿色', disabled=False, description='背景颜色模式')\n",
    "\n",
    "# -------------------------------交互设置-------------------------------\n",
    "interact_manual(webcam_opencv, \n",
    "                device_index = device_index,\n",
    "                quit_key = quit_key,\n",
    "                pause_key = pause_key,\n",
    "                is_autoSaveFrame = is_autoSaveFrame,\n",
    "                frame_saveDir = frame_saveDir,\n",
    "                frame_dirName = frame_dirName,\n",
    "                frame_nSave = frame_nSave,\n",
    "                auto_frameNum = auto_frameNum,\n",
    "                is_handSaveFrame = is_handSaveFrame,\n",
    "                frame_capKey = frame_capKey,\n",
    "                is_resizeFrame = is_resizeFrame,\n",
    "                resize_frame = resize_frame,\n",
    "                resizeRatio_frame = resizeRatio_frame,\n",
    "                frame_namePrefix = frame_namePrefix,\n",
    "                frame_saveStyle = frame_saveStyle,\n",
    "                jpg_quality = jpg_quality,\n",
    "                png_quality = png_quality,\n",
    "                logName = logName,\n",
    "                logMode = logMode,\n",
    "                is_compress = is_compress,\n",
    "                compressStyle = compressStyle,\n",
    "                is_autoCompressName = is_autoCompressName,\n",
    "                compressName = compressName,\n",
    "                compressMode = compressMode,\n",
    "               is_rmbgColor = is_rmbgColor,\n",
    "               rmbgColorMode = rmbgColorMode)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b6bbf4a0-db17-4727-96f0-ba6370b7eae6",
   "metadata": {},
   "source": [
    "<h3 align=\"center\">⚡ 使用教程</h3>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d9aa080a-d5ee-491e-a2a1-977664713952",
   "metadata": {},
   "source": [
    "<div align=\"center\" >\n",
    "<img src=\"https://pycver.gitee.io/ows-pics/imgs/countdown.png\">\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6961c53a-a334-4c2a-b8de-1f52ebda8828",
   "metadata": {},
   "source": [
    "#### 💡 常规调用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "58307de4-173b-46a9-b30d-c12cfe4a1de2",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# 默认按q键退出\n",
    "!python opencv_webcam.py"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7ceb44c6-5434-4f28-ae05-fe10d8def815",
   "metadata": {},
   "source": [
    "#### 💡 设备选择"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6bc38dd9-698f-4dbc-8249-2743ac8d3f18",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 多摄像头切换示例，默认为0\n",
    "!python opencv_webcam.py -dev 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "654a4892-6d92-45ce-8baa-4ebdc50b6aed",
   "metadata": {},
   "outputs": [],
   "source": [
    "!python opencv_webcam.py -dev 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8bf0171b-977d-4db2-8864-4832886a6d97",
   "metadata": {},
   "outputs": [],
   "source": [
    "!python opencv_webcam.py -dev 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8f846baa-f487-4625-bfb4-75035c042e80",
   "metadata": {},
   "outputs": [],
   "source": [
    "# RTSP\n",
    "!python opencv_webcam.py -dev rtsp://username:password@xxx.xxx.xxx"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8bc2584c-ea5f-414f-bb71-1b422b319853",
   "metadata": {},
   "source": [
    "#### 💡 设置退出键"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "53eccc33-5076-4158-93b3-1e06fa1d84ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 默认按q键退出\n",
    "!python opencv_webcam.py -q z # 设置z键退出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d5c3436e-d84c-4871-942f-f65c82b6320e",
   "metadata": {},
   "outputs": [],
   "source": [
    "!python opencv_webcam.py -q k # 设置k键退出"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "58ed4f93-c650-4b7e-b28a-9daab41914bf",
   "metadata": {},
   "source": [
    "<div align=\"center\" >\n",
    "<img src=\"https://pycver.gitee.io/ows-pics/imgs/webcam2frames.png\">\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "53b53248-4cd5-4221-b632-25b387bdec05",
   "metadata": {},
   "source": [
    "#### 💡 自动保存帧"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f04eab9b-f7fc-42a0-a3df-6d546bcde5d9",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# 视频帧自动保存\n",
    "!python opencv_webcam.py -isasf"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "581cd5e6-9a32-4dc6-94f6-beb5ae64f749",
   "metadata": {},
   "source": [
    "<div align=\"center\" >\n",
    "<img src=\"https://pycver.gitee.io/ows-pics/imgs/pre_save_imgs.png\">\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "91cc1ea9-ce8d-40e5-aefd-4118696ea018",
   "metadata": {},
   "source": [
    "#### 💡 每隔n帧保存一次帧"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "acaf3636-8f83-47af-8161-2614a24cf3cc",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# 每隔10帧保存一次帧\n",
    "!python opencv_webcam.py -isasf -fns 10"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c4587772-b8be-4c07-9469-c71c69d6b020",
   "metadata": {},
   "source": [
    "#### 💡 手动保存帧"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6b564768-4ea4-4081-a9e8-6799dd862ef8",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# 默认按a键捕获一帧\n",
    "!python opencv_webcam.py -ishsf"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f3e924ed-612d-4c1d-873a-786aacc57937",
   "metadata": {},
   "source": [
    "#### 💡 自定义捕获键"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bbf16f8a-50fb-41f6-8c6d-31152ce29217",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 设置z键为捕获键\n",
    "!python opencv_webcam.py -ishsf -fck z"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0677cd5a-007f-4743-82a8-f533d108e6ba",
   "metadata": {},
   "source": [
    "#### 💡 重塑帧尺寸（自定义宽高）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b5be8596-d7c4-4f30-bdec-b2ac1ab31479",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 重塑宽度300 高度200\n",
    "!python opencv_webcam.py -isasf -isrf -rf 300,200 # 自动版，v0.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e61711ff-57a4-4723-bbcf-a8dbf9bf9f5c",
   "metadata": {},
   "outputs": [],
   "source": [
    "!python opencv_webcam.py -ishsf -isrf -rf 300,200 # 手动版"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b05047c0-0714-4170-9dea-13b718b1bd5d",
   "metadata": {},
   "source": [
    "#### 💡 重塑帧尺寸（自定义宽高缩放比）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "17d4f042-bcf5-4040-9737-ce5b927c13b2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 宽高缩放比为0.5\n",
    "!python opencv_webcam.py -isasf -isrf -rrf 0.5 # 自动版"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "72f49465-8306-4e86-9e1a-4203588f3abf",
   "metadata": {},
   "outputs": [],
   "source": [
    "!python opencv_webcam.py -ishsf -isrf -rrf 0.5 # 手动版"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6c0bc300-8aa7-4028-aea6-ef806f6c8118",
   "metadata": {},
   "source": [
    "#### 💡 自定义保存路径"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "46f48201-9608-4122-a0d0-ac226e46eaac",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# 设置保存路径，默认保存路径为WebcamFrame\n",
    "!python opencv_webcam.py -fsd custom_dir -isasf # 以自动版为例"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "77054e11-6869-49d3-b810-919614c5a25f",
   "metadata": {},
   "source": [
    "#### 💡 自定义帧目录名称"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7cf58077-be7d-4f1b-ab1e-a88004ffbee3",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 设置帧目录名称，默认保存路径为frames\n",
    "!python opencv_webcam.py -fdn frames_custom -isasf # 以自动版为例"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0078a79f-81a8-4e41-9290-b9349f44fa02",
   "metadata": {},
   "source": [
    "#### 💡 自定义帧名前缀"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5b34e67f-0e25-43ff-aec1-ef3ed74f7fd8",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# 设置帧图片的前缀名称\n",
    "!python opencv_webcam.py -isasf -fnp webcam # 以自动版为例"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bb695981-2e72-4277-a67b-4b2e0ad1524c",
   "metadata": {},
   "source": [
    "#### 💡 设置帧保存格式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "387d62f8-5e9b-4141-8e90-3d2c13381d57",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 设置JPG质量为100，默认为95\n",
    "!python opencv_webcam.py -isasf -fss jpg -jq 100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "67bc819d-73ee-41bb-b8ed-6148f6476c24",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 设置PNG质量为5，默认为3\n",
    "!python opencv_webcam.py -isasf -fss png -pq 5"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c224bfc6-5f9b-42f9-b952-d90106992317",
   "metadata": {},
   "source": [
    "#### 💡 设置暂停键"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7cc860c3-e8a0-4e65-95c1-123f84c21c09",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# 设置w键为暂停键，默认为p键\n",
    "!python opencv_webcam.py -p w # 按任意键继续"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "be8a8ff7-d659-4df2-a92b-7ae08879c477",
   "metadata": {},
   "source": [
    "#### 💡 设置保存帧数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "13f16a9e-cc3c-4b41-b23b-6383b36c5c16",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# 设置保存100帧\n",
    "!python opencv_webcam.py -isasf -afn 100"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7177a76c-61f8-4097-8889-69318b985149",
   "metadata": {},
   "source": [
    "<div align=\"center\" >\n",
    "<img src=\"https://pycver.gitee.io/ows-pics/imgs/webcam2log.png\">\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "56a703c9-f0d3-4e98-aca3-8779b13cd6e0",
   "metadata": {},
   "source": [
    "#### 💡 日志设置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "990489b6-1a95-4ca7-bfcc-034cf500281b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 日志文件默认保存在项目根目录，ows.log\n",
    "!python opencv_webcam.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9bb60da5-3ac2-4fc7-acbd-912bfe7f1b3a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 设置日志文件名称及类型，类型包括.log、.txt、.data\n",
    "!python opencv_webcam.py -ln ows.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "43215afb-c557-47b1-905e-bfa69a77e6b2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 设置日志保存方式，，默认为追加模式\n",
    "!python opencv_webcam.py - lm w  # 设置为覆盖模式"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "931b99f3-8292-40bf-a036-3a66e8b75b1b",
   "metadata": {},
   "source": [
    "<div align=\"center\" >\n",
    "<img src=\"https://pycver.gitee.io/ows-pics/imgs/frames2zip.png\">\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "edb18013-276c-48a6-8f7f-3279c51607b1",
   "metadata": {},
   "source": [
    "#### 💡 频帧压缩"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d43e5f15-4fa1-4670-844f-8a8c1d057888",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 常规压缩，默认ows.zip（以自动版为例）\n",
    "!python opencv_webcam.py - isasf - isc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "aa58d33a-2e14-4d16-9c39-e81d9aef24a8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 自定义压缩文件名称\n",
    "!python opencv_webcam.py -isasf -isc -cn ows02"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3fa65a77-f240-4a80-bf8b-3eadea172798",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 自动命名压缩文件\n",
    "!python opencv_webcam.py -isasf -isc -isacn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0db6b23c-9bd8-4c3f-9917-d0a91a354d7b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 自定义压缩模式，默认为写覆盖\n",
    "!python opencv_webcam.py -isasf -isc -cs tar -cm w:gz # tar压缩"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cc582e63-ec28-4ecb-892c-d91a835cdb18",
   "metadata": {},
   "outputs": [],
   "source": [
    "!python opencv_webcam.py -isasf -isc -cm a # 追加模式(a模式仅限zip) 注：该指令仅限v0.4"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0af95d24-87a8-44d9-b20b-d1018ae688af",
   "metadata": {},
   "source": [
    "<div align=\"center\" >\n",
    "\t<img src=\"https://pycver.gitee.io/ows-pics/imgs/rm_bgColor.png\">\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9c1791a9-9b31-4763-a39e-79c1a66762e0",
   "metadata": {},
   "source": [
    "<div align=\"center\">\n",
    "\t<img src=\"https://pycver.gitee.io/ows-pics/imgs/green.jpg\" width=\"20%\"/>\n",
    "\t<img src=\"https://pycver.gitee.io/ows-pics/imgs/remove_green.png\" width=\"20%\"/>\n",
    "\t<img src=\"https://pycver.gitee.io/ows-pics/imgs/blue.jpg\" width=\"20%\"/>\n",
    "\t<img src=\"https://pycver.gitee.io/ows-pics/imgs/remove_blue.png\" width=\"20%\"/>\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4dceeef9-b7b7-4305-8509-9e4ab78e66e7",
   "metadata": {},
   "source": [
    "#### 💡 去除背景色（抠绿、抠蓝）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cd531ac1-36f7-445c-8465-ec70ff847683",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 去除背景色，默认为绿色\n",
    "!python opencv_webcam.py -isasf -isrbgc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "47c22f38-7b90-4a36-99aa-5676b9ff8c32",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 选择背景色模式\n",
    "!python opencv_webcam.py -isasf -isrbgc -rbgcm green # 抠绿"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d6ecc136-7d55-48d6-8c21-7b94eca8fff9",
   "metadata": {},
   "outputs": [],
   "source": [
    "!python opencv_webcam.py -isasf -isrbgc -rbgcm blue # 抠蓝"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "129ad574-f290-4a68-b8ce-160c27cdb340",
   "metadata": {},
   "source": [
    "#### 💡指令查询"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fcb03330-b662-4d49-b302-32c70ec40104",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# 查询脚本参数\n",
    "!python opencv_webcam.py --help"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
